package com.xsdl.chain.verifier;

import com.xsdl.chain.annonation.Length;

import java.lang.reflect.Field;

public class LengthVerifier implements Validator {

    @Override
    public void validate(Field field, Object value, ValidatorContext context) {
        Length length = field.getAnnotation(Length.class);
        if (length != null) {
            int len = length.value();
            if (value instanceof String) {
                String v = (String) value;
                if (v.length() != len) {
                    context.appendErrMsg(field.getName() + "当前值为:" + v + ",与要求长度:" + len + "不一致");
                }
            }
        }
    }

}
